package com.guang.springbootexception.controller;

import com.guang.springbootexception.bean.ResultData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liguang
 * @date 2022/5/17 17:35
 */
@RestController
public class HelloController {

    private static final Logger logger = LoggerFactory.getLogger(HelloController.class);

    //    @GetMapping("/hello")
//    public ResultData<String> getStr() {
//        return ResultData.success("hello,javadaily");
//    }
    @GetMapping("/hello")
    public String getStr() {
        return "hello,javadaily";
    }

//    @GetMapping("/wrong")
//    public int error() {
//        int i = 9 / 0;
//        return i;
//    }

    @GetMapping("/wrong")
    public int error() {
        int i;
        try {
            i = 9 / 0;
        } catch (Exception e) {
            logger.error("error:{}", e);
            i = 0;
        }
        return i;
    }

    @GetMapping("error1")
    public void empty(){
        throw  new RuntimeException("自定义异常");
    }
}